import {combineReducers} from 'redux'
import {SEQUENTIAL_PLAY, 
        RANDOM_PLAY , 
        LOOP_PALY, 
        SET_MUSIC_LIST, 
        CURRENTMUSIC, 
        CURRENTLYRIC, 
        SETPLAYING,
        SETAUDIO
        } from './action-types'
//将多个reducer合成为一个state状态

function musicList(state=[],action){
    switch (action.type) {
        case SET_MUSIC_LIST:
            return action.data
        default:
            return state
    }
}
//播放模式
function palyMode(state=SEQUENTIAL_PLAY,action){
    switch (action.type) {
        case SEQUENTIAL_PLAY:
            return SEQUENTIAL_PLAY
        case RANDOM_PLAY:
            return RANDOM_PLAY
        case LOOP_PALY:
            return LOOP_PALY
        default:
            return state
    }
}

//当前播放的音乐  索引位置
function currentMusic(state=-1,action){
    switch (action.type) {
        case CURRENTMUSIC:
            return action.data
        default:
          return state
    }
}

//当前歌曲歌词
function currentLyric(state={},action){
    switch (action.type) {
        case CURRENTLYRIC:
            return action.data
        default:
           return state
    }
}

//是否正在播放
function Playing(state=false,action){
    switch (action.type) {
        case SETPLAYING:
            return action.data        
        default:
            return state
    }
}

//播放对象
function audio(state={},action){
    switch (action.type) {
        case SETAUDIO:
            return action.data
        default:
            return state
    }
}



export default combineReducers({musicList, palyMode,currentMusic, currentLyric, Playing, audio})
